const path = require('path');

const setPath = url => path.resolve(__dirname, url);

const isProduction = process.env.NODE_ENV !== 'development';

const packageName = 'homepage';

module.exports = {
  publicPath: 'http://192.168.1.13:8081/',
  outputDir: 'dist',
  assetsDir: 'static',
  productionSourceMap: false,
  configureWebpack: {
    output: {
      libraryTarget: 'umd',
      library: `${packageName}-[name]`,
      jsonpFunction: `webpackJsonp_${packageName}`
    },
    externals: isProduction ? {
      vue: 'Vue',
      'vue-router': 'VueRouter',
    } : {}
  },
  chainWebpack: (config) => {
    // 添加别名
    config.resolve.alias
      .set('@', setPath('src'))
      .set('@images', setPath('src/assets/images'))
      .set('@styles', setPath('src/assets/styles'));
    // 修复HMR
    config.resolve.symlinks(true);
    // 删除预加载
    config.plugins.delete('prefetch');
    config.plugins.delete('preload');
  },
  css: {
    extract: isProduction,
    sourceMap: !isProduction,
  },
  parallel: require('os').cpus().length > 1,
  devServer: {
    port: 8081,
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    open: false,
    compress: false,
    overlay: {
      warnings: true,
      errors: true,
    },
    proxy: null,
  },
};
